# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=chipmunk
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
# Please don't update chipmunk until cocos2d-x support 7.x :)
pkgver=6.2.2
pkgrel=1
pkgdesc="A high-performance 2D rigid body physics library (mingw-w64)"
arch=('any')
url="https://chipmunk-physics.net/"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
source=("https://github.com/slembcke/Chipmunk2D/archive/Chipmunk-${pkgver}.tar.gz"
        001-build-fix.patch
        001-fix-install-locations.patch)
sha256sums=('c51f0e3a30770f6b940de3228bee40a871aaf7611a1b5ec546a7d2b9e1041f97'
            '5000228fe30ed95d465a510fb002a809ecfd753341967888e3fe49a5aa773d89'
            'a941ca86cc475025c273142901d242d8845e2e6ab1e8ddec47d2b54ce41feb9b')
options=(staticlibs !buildflags !strip)

prepare() {
  cd ${srcdir}/Chipmunk2D-Chipmunk-${pkgver}
  #patch -p1 -i ${srcdir}/001-build-fix.patch
  patch -p1 -i ${srcdir}/001-fix-install-locations.patch
}

build() {

  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_DEMOS=OFF \
    -DBUILD_SHARED=ON \
    -DINSTALL_STATIC=ON \
    ../Chipmunk2D-Chipmunk-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR=${pkgdir} install
}
